package com.night.administration.service.impl;

import com.night.administration.mapper.StructureMapper;
import com.night.administration.service.StructureService;
import com.night.common.entity.administration.Structure;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: StructureServiceImpl
 * @Description: //TODO
 * @author: LZJ
 * @date: 2022/10/19-9:35
 * @version: v1.0
 */
@Service("StructureService")
@Transactional
public class StructureServiceImpl implements StructureService {
    @Resource
    private StructureMapper structureMapper;

    @Override
    public void insert(Structure structure) {

        structureMapper.insert(structure);
    }

    @Override
    public void update(Structure structure) {
        structureMapper.update(structure);
    }

    @Override
    public List<Structure> getCollege() {
        List<Structure> colleges = structureMapper.getCollege();
        List<Structure> newCollege = new ArrayList<>();
        for (Structure college : colleges) {
            if (newCollege.isEmpty()) {
                newCollege.add(college);
            } else {
                boolean isSame = false;
                for (Structure s1 : newCollege) {
                    if (college.getCollege().equals(s1.getCollege())) {
                        isSame = true;
                        break;
                    }
                }
                if (!isSame) {
                    newCollege.add(college);
                }
            }
        }
        return newCollege;
    }

    @Override
    public List<Structure> getMajorByCollege(String college) {
        return structureMapper.getMajorByCollege(college);
    }
}
